This article provides an overview and how-to instructions for updating documents within Ditto.
UPDATE
When executing UPDATE
to apply changes, only the minimum data necessary to enforce all peers converge on one view of the data sync across the mesh. (Updating)INSERT
While INSERT
operations modify all provided fields, even if they remain unchanged. (Inserting to Update)UPDATE
method instead.
UPDATE
operation on the cars
collection:
ATTACHMENT
object is created and linked to a document, it becomes immutable, meaning its contents cannot be changed.
However, you can indirectly update attachments by performing an UPDATE
operation on the document to replace the existing attachment token with a different one. The attachment token is the reference pointer linking the document to the attachment’s binary data stored separately.
MAP
to a document, use the operator syntax -> (...)
, allowing you to edit multiple child fields within a single MAP
:
UPDATE
operation modifying all documents in the cars collection that are currently red, and changing their color to blue.
After the update, you can reference the documents modified by the mutatedDocumentIDs
method on the result
of the update.
INSERT
operation provides conflict policy options to override default behavior if a document with the same ID already exists.
ON ID CONFLICT DO UPDATE
policy, inserted documents automatically apply updates for all provided fields.
UPDATE
method.MAP
within another MAP
to establish a parent-child relationship within a document as follows: